<template>
    <div>
        <router-link tag="div" to='/' class="header-abs" v-show="showAbs">
             <span class="iconfont header-abs-back">&#xe605;</span>
        </router-link> 
        <router-link tag="div" to='/' class="header-fixed" v-show="!showAbs" :style="opacityStyle">
             景点详情
             <span class="iconfont header-fixed-back">&#xe605;</span>
        </router-link>
    </div>
    
</template>
<script>
export default {
    name:'detailHeader',
    data(){
        return{
            showAbs:true,
            opacityStyle:{
                opacity:0
            }
        }
    },
    methods:{
        handleScroll(){
           console.log('scroll');
           const top=document.documentElement.scrollTop;
            if(top>60){
                let opacity=top/140;
                opacity=opacity>1?1:opacity
                this.showAbs=false;
                this.opacityStyle={
                    opacity
                }
            }else{
                this.showAbs=true
            }
        }
    },
    activated(){//绑定
        window.addEventListener('scroll',this.handleScroll);
    },
    deactivated(){//解绑
        window.removeEventListener('scroll',this.handleScroll);
    }
}
</script>
<style lang="stylus" scoped>
@import '~@/assets/styles/varibies.styl';
    .header-abs
        position :absolute
        left :.2rem
        top:.2rem
        width :.8rem
        height :.8rem
        border-radius :.4rem
        background :rgba(0,0,0,.8)
        text-align :center
        line-height :.8rem
        .header-abs-back
            color :#fff
            font-size :.4rem
    .header-fixed
        position fixed
        top:0
        left:0
        right :0
        overflow :hidden
        height :$headerHeight
        line-height :$headerHeight
        text-align :center
        color :#ffffff
        background :$bgColor
        z-index:2
        .header-fixed-back
            position:absolute
            top:0
            left:0
            width :.64rem
            text-align:center
            font-size: 0.4rem


</style>
